from os.path import splitext as _splitext
from cv2 import VideoCapture as _VideoCapture, imwrite as _imwrite
__all__ = [
    "video2imgs",
]


def video2imgs(filename):
    cap = _VideoCapture(filename)
    fname = _splitext(filename)[0]
    count=0
    while(cap.isOpened()):
        ret,frame=cap.read()
        if not ret:
            break;
        #gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        #resized = cv2.resize(gray, (RESIZED_W, RESIZED_H))
        _imwrite(fname+'\\'+str(count).zfill(4)+".jpg", frame)  # bmp处理速度快占空间多
        count+=1
    cap.release()
    return count
